Page({
  data: {
    showView: false,
    content:'',
    modalHidden: true,
    img:'',
    imgalist:[]
  },
  Tianapi: function () {
    this.onLoad();
  },
  onLoad: function () {
    var that = this
    wx.request({
      url: 'https://api.tianapi.com/txapi/saylove/', //天行数据土味情话接口
      data: {
        key: '9b1e305899153e3f07eeddd594c2b5f2'  //apikey请在https://www.tianapi.com中获得
      },
      success: function (res) {
        if (res.data.code == 200) {
          that.setData({
            content: res.data.newslist[0].content
          })
        } else {
          that.setData({
            content: res.data.msg
          })
        }
      },
      fail: function (err) {
        console.log(err)
      }
    })
    
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: (res) => {
    if (res.from === 'button') {
      console.log("来自页面内转发按钮");
      console.log(res.target);
    }
    else {
      console.log("来自右上角转发菜单")
    }
    return {
      title: '安利一段土味情话~',
      path: '/pages/iconlist/iconlist',
      
      success: (res) => {
        console.log("转发成功", res);
      },
      fail: (res) => {
        console.log("转发失败", res);
      }

    }

  },
  onChangeShowState: function () {
    var that = this;
    that.setData({
      showView: (!that.data.showView)
    })
  },
  onChangehideState: function () {
    
    this.setData({
      showView: false
    })
  },
  /**
   * 点击取消
   */
  modalCandel: function() {
    // do something
    this.setData({
      modalHidden: true
    })
  },

  /**
   *  点击确认
   */
  modalConfirm: function() {
    // do something
    this.setData({
      modalHidden: true
    })
  },

  preview:function(event){
    
    let currentUrl = event.currentTarget.dataset.src
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: this.data.imgList // 需要预览的图片http链接列表
    })
  },
  // 分享海报
  shareHb(){
    wx.showToast({
      title: '开发中',
    })
    return
    wx.showLoading({
      title:'加载中'
    })
    var that = this
    //console.log(that.data.content);return false;
    wx.request({
      url: 'https://blog.zlx3323.com.cn/demo/sharecode.php?content=' + that.data.content, //图片接口
      data: {},
      success: function (res) {
        if (res.data.code == 200) {
          that.setData({
            img: res.data.img,
            modalHidden:false,
            imgList:[res.data.img]
          })
          
          wx.hideLoading()
          
        } else {
          that.setData({
            img: res.data
          })
        }
      },
      fail: function (err) {
        console.log(err)
      }
      
    })
  },
})
